using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Logger;

namespace FiltronASP.Models.DAO.Filtron
{
    public class FiltronFilterTypeShapeDAO : Abstracts.AbstractGenericDAO<FiltronFilterTypeShape, System.Nullable<int>>,
        Interfaces.Filtron.IFiltronFilterTypeShapeDAO
    {
        /// <summary>
        /// Metoda zwracajaca nazwe parametru bedacego kluczem glownym tabeli.
        /// </summary>
        /// <returns>nazwa klucza glownego</returns>
        protected override string GetKeyProperty()
        {
            return "type_shape_id";
        }

        /// <summary>
        /// Pobieranie obiektow na podstawie ksztaltu i typu.
        /// </summary>
        /// <param name="typeId">typ</param>
        /// <param name="shapeId">ksztalt</param>
        /// <returns>rekordy o zadanym typie i ksztalcie lub null, gdy nie ma</returns>
        public IQueryable<FiltronFilterTypeShape> FindByTypeAndShape(int shapeId, int typeId)
        {
            if (typeId.Equals(0) || shapeId.Equals(0))
            {
                return null;
            }   //if
            try
            {
                IQueryable<FiltronFilterTypeShape> typeShapes = this._cmsEntitiesDataContext.FiltronFilterTypeShapes.Where(
                    tysh => tysh.type_id.Equals(typeId) && tysh.shape_id.Equals(shapeId)
                        );
                if (!(typeShapes.Any()))
                {
                    return null;
                }   //if
                return typeShapes;
            }   //try
            catch (Exception ex)
            {
                MyLogger.Log(ex);
            }   //catch
            return null;
        }

        public IQueryable<FiltronFilterTypeShape> FindByDictIdAndDictKind(int dictId, int dictKind)
        {
            if (dictId.Equals(0) || dictKind.Equals(0))
            {
                return null;
            }   //if
            try
            {
                IQueryable<FiltronFilterTypeShape> typeShapes = this._cmsEntitiesDataContext.FiltronFilterTypeShapes.Where(
                    tysh => tysh.dict_id.Equals(dictId) && tysh.dict_kind.Equals(dictKind)
                        );
                if (!(typeShapes.Any()))
                {
                    return null;
                }   //if
                return typeShapes;
            }   //try
            catch (Exception ex)
            {
                MyLogger.Log(ex);
            }   //catch
            return null;
        }

    }
}
